<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Snoop</title>
<%@ page import="javax.servlet.http.HttpUtils,java.util.Enumeration" %>
</head>
<body>

<H1>JSP Snoop page</H1>

<h2>OS Name</h2>
<jsp:scriptlet>
   String s;
   s = "java.vm.name";
   out.println(s+": "+System.getProperty(s)+"&lt;br/>");
   s = "java.vm.version";
   out.println(s+": "+System.getProperty(s)+"&lt;br/>");
   s = "os.name";
   out.println(s+": "+System.getProperty(s)+"&lt;br/>");
   s = "os.version";
   out.println(s+": "+System.getProperty(s)+"&lt;br/>");
</jsp:scriptlet>
<%--
<jsp:scriptlet>
   String s;
   s = "java.vm.name";
   s = "os.name";
   out.println("OS Name"+": "+System.getProperty(s)+"");
   s = "os.version";
   out.println(""+System.getProperty(s)+"");
</jsp:scriptlet>
--%>
<H2>Context information</H2>
<TABLE>
<TR>
	<TH align=right>Server Info:</TH>
	<TD><%= application.getServerInfo() %></TD>
</TR>
</TABLE>

<H2>Request information</H2>

<TABLE>
<TR>
	<TH align=right>Requested URL:</TH>
	<TD><%= HttpUtils.getRequestURL(request) %></TD>
</TR>
<TR>
	<TH align=right>Request method:</TH>
	<TD><%= request.getMethod() %></TD>
</TR>
<TR>
	<TH align=right>Request URI:</TH>
	<TD><%= request.getRequestURI() %></TD>
</TR>
<TR>
	<TH align=right>Request protocol:</TH>
	<TD><%= request.getProtocol() %></TD>
</TR>
<TR>
	<TH align=right>Servlet path:</TH>
	<TD><%= request.getServletPath() %></TD>
</TR>
<TR>
	<TH align=right>Path info:</TH>
	<TD><%= request.getPathInfo() %></TD>
</TR>
<TR>
	<TH align=right>Path translated:</TH>
	<TD><%= request.getPathTranslated() %></TD>
</TR>
<TR>
	<TH align=right>Query string:</TH>
	<TD><%= request.getQueryString() %></TD>
</TR>
<TR>
	<TH align=right>Content length:</TH>
	<TD><%= request.getContentLength() %></TD>
</TR>
<TR>
	<TH align=right>Content type:</TH>
	<TD><%= request.getContentType() %></TD>
<TR>
<TR>
	<TH align=right>Server name:</TH>
	<TD><%= request.getServerName() %></TD>
<TR>
<TR>
	<TH align=right>Server port:</TH>
	<TD><%= request.getServerPort() %></TD>
<TR>
<TR>
	<TH align=right>Remote user:</TH>
	<TD><%= request.getRemoteUser() %></TD>
<TR>
<TR>
	<TH align=right>Remote address:</TH>
	<TD><%= request.getRemoteAddr() %></TD>
<TR>
<TR>
	<TH align=right>Remote host:</TH>
	<TD><%= request.getRemoteHost() %></TD>
<TR>
<TR>
	<TH align=right>Authorization scheme:</TH>
	<TD><%= request.getAuthType() %></TD>
<TR>
</TABLE>

<%
	Enumeration e = request.getHeaderNames();
	if(e != null && e.hasMoreElements()) {
%>
<H2>Request headers</H2>

<TABLE>
<TR>
	<TH align=left>Header:</TH>
	<TH align=left>Value:</TH>
</TR>
<%
		while(e.hasMoreElements()) {
			String k = (String) e.nextElement();
%>
<TR>
	<TD><%= k %></TD>
	<TD><%= request.getHeader(k) %></TD>
</TR>
<%
		}
%>
</TABLE>
<%
	}
%>


<%
	e = request.getParameterNames();
	if(e != null && e.hasMoreElements()) {
%>
<H2>Request parameters</H2>
<TABLE>
<TR valign=top>
	<TH align=left>Parameter:</TH>
	<TH align=left>Value:</TH>
	<TH align=left>Multiple values:</TH>
</TR>
<%
		while(e.hasMoreElements()) {
			String k = (String) e.nextElement();
			String val = request.getParameter(k);
			String vals[] = request.getParameterValues(k);
%>
<TR valign=top>
	<TD><%= k %></TD>
	<TD><%= val %></TD>
	<TD><%
			for(int i = 0; i < vals.length; i++) {
				if(i > 0)
					out.print("<BR>");
				out.print(vals[i]);
			}
		%></TD>
</TR>
<%
		}
%>
</TABLE>
<%
	}
%>

<%
	e = getServletConfig().getInitParameterNames();
	if(e != null && e.hasMoreElements()) {
%>
<H2>Init parameters</H2>
<TABLE>
<TR valign=top>
	<TH align=left>Parameter:</TH>
	<TH align=left>Value:</TH>
</TR>
<%
		while(e.hasMoreElements()) {
			String k = (String) e.nextElement();
			String val = getServletConfig().getInitParameter(k);
%>
<TR valign=top>
	<TD><%= k %></TD>
	<TD><%= val %></TD>
</TR>
<%
		}
%>
</TABLE>
<%
// Attributes available from Jserv

       String prefix = "org.apache.jserv.";
       Object attrsObj = request.getAttribute("org.apache.jserv.attribute_names");
       if ( attrsObj != null && attrsObj instanceof Enumeration ) {
           Enumeration attrs = (Enumeration) attrsObj;
%>
 <P>
<H1>JServ Attributes</H1>
available via HttpServletRequest.getAttribute()
<BR>
<TABLE>
<%
           while ( attrs.hasMoreElements()) {
               String attr = attrs.nextElement().toString();
%>
<TR><TD>
<%
               if ( request.getAttribute(prefix + attr) != null ) {
                   out.println( prefix + attr + "</TD><TD>" +
                       request.getAttribute(prefix + attr).toString());
               } else {
                   out.println( prefix + attr + "</TD><TD>NULL " );
               }
%>
</TD></TR>
<%

           }
       }
%>
</TABLE>
<%
	}
%>

</BODY>
</HTML>